import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

let noLog = {
  id: Number,
  pas: "",
  power: ""
};

export default new Vuex.Store({
  state: {
    token: noLog
  },
  mutations: {
    LOGIN: (state, data) => {
      //更改token的值
      state.token = data;
      uni.setStorageSync("id", state.token.id);
      uni.setStorageSync("pas", state.token.pas);
    },
    LOGOUT: state => {
      //登出的时候要清除token
      state.token = noLog;
      uni.removeStorageSync("id");
      uni.removeStorageSync("pas");
    }
  },
  actions: {
    UserLogin({ commit }, data) {
      commit("LOGIN", data);
    },
    UserLogout({ commit }) {
      commit("LOGOUT");
    }
  },
  modules: {}
});
